package com.shuorikeji.huohuo.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bytedance.sdk.djx.model.DJXDrama;
import com.google.android.material.imageview.ShapeableImageView;
import com.shuorikeji.huohuo.R;
import com.shuorikeji.huohuo.bean.DjHisInfoBean;
import com.shuorikeji.huohuo.callback.ClickCallBack;
import com.shuorikeji.huohuo.common.Constant;
import com.shuorikeji.huohuo.utils.BusinessUtils;

import java.util.ArrayList;
import java.util.List;

import androidx.recyclerview.widget.RecyclerView;

public class DjSeeHisAdapter extends RecyclerView.Adapter<DjSeeHisAdapter.BaseViewHolder> {
    private final Context mContext;
    private List<DJXDrama> mData = new ArrayList<>();
    private ClickCallBack callBack;

    public DjSeeHisAdapter(Context context, ClickCallBack callBackFlag) {
        this.mContext = context;
        this.callBack = callBackFlag;
    }

    @Override
    public BaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.dj_see_his_item_layout, parent, false);
        BaseViewHolder holder = new BaseViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(BaseViewHolder holder, @SuppressLint("RecyclerView") int position) {
        //holder.ivSec.setVisibility((mData.get(position).isShowCzType()) ? View.VISIBLE : View.GONE);
        //holder.ivSec.setImageResource((mData.get(position).isSec()) ? R.mipmap.icon_ls_cz_sec : R.mipmap.icon_ls_cz_un_sec);
        BusinessUtils.setLoadImg(mContext, mData.get(position).coverImage, holder.sivFm);
        holder.tvTitle.setText(mData.get(position).title);
        holder.tvZj.setText(mData.get(position).type);
        //holder.tvTime.setText("观看时间：" + BusinessUtils.longTimeToDateStr(mData.get(position).getUpdate_time(), "yyyy-MM-dd HH:mm:ss"));
        holder.ivSec.setOnClickListener(view -> {
            if (callBack != null) {
                callBack.onClick(2, mData.get(position));
            }
        });
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (callBack != null) {
                    callBack.onClick(1, mData.get(position));
                }
            }
        });
    }

    public void setData(List<DJXDrama> data) {
        if (mData != null) {
            mData.clear();
            mData.addAll(data);
            notifyDataSetChanged();
        }
    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    class BaseViewHolder extends RecyclerView.ViewHolder {
        TextView tvTitle;
        ShapeableImageView sivFm;
        TextView tvZj;
        TextView tvTime;
        ImageView ivSec;

        public BaseViewHolder(View itemView) {
            super(itemView);
            tvTitle = itemView.findViewById(R.id.tv_title);
            sivFm = itemView.findViewById(R.id.siv_fm);
            tvZj = itemView.findViewById(R.id.tv_zj);
            tvTime = itemView.findViewById(R.id.tv_time);
            ivSec = itemView.findViewById(R.id.iv_sec);
        }
    }
}
